<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 상품 구매 안내 컨트롤러
 */
class Product extends CI_Controller {
	
	var $data = array();
	
	function __construct() {
		parent::__construct();

		$this->data['sess_userinfo'] = $this->session->userdata('userinfo');

		$this->load->model('product/Cashpoint_model', 'cashpoint');
		$this->load->model('product/Package_model', 'package');
		$this->load->model('mypage/Member_model', 'member');
	}

	// Default
	function index() {
		
	}

	/**
	 * 캐쉬 충전 안내페이지
	 */
	function cash() {
		log_message('debug',"@@@@ Product::cash()");

		// 보유 포인트를 보여준다.
		// $member_point = $this->member->get_member_point($this->data['sess_userinfo']['user_id']);
		// $this->data['cashpoint'] = $member_point['cash']+$member_point['point'];

		$this->data['cashpoint_list']   = $this->cashpoint->select_cash_to_point_list();
		$this->load->view('product/cash_v', $this->data);
	}
	
	/**
	 * 패키지 상품 구매 안내페이지
	 */
	function package() {
		log_message('debug',"@@@@ Product::package()");
		
		// 사용중인 패키지가 있는지 체크
		$this->data['is_package'] = FALSE;
		$member_package = $this->member->get_member_package($this->data['sess_userinfo']['user_id']);
		if ($member_package['package_cd'] != PREM_GENERAL) {
			$this->data['is_package'] = TRUE;
		}
		
		$this->data['package_list']   = $this->package->select_package_with_coupon_list();
		$this->load->view('product/package_v', $this->data);
	}
	
	/**
	 * 패키지 결제 선택 페이지
	 */
	function buy_package() {
		log_message('debug',"@@@@ Product::buy_package()");

		$p_type = $this->input->post('p_type');

		$package = $this->package->get_package($this->input->post('package_cd'));

		$this->data['choice_item']['p_type']       = $p_type;
		$this->data['choice_item']['p_type_name']  = '패키지 상품';
		$this->data['choice_item']['package_cd']   = $package['package_cd'];
		$this->data['choice_item']['package_name'] = $package['package_name'];
		$this->data['choice_item']['price']        = $package['price_vat'];
		
		$this->load->view('product/buy_package_pop_v', $this->data);
	}

	/**
	 * 캐쉬 결제 선택 페이지
	 */
	function buy_cash() {
		log_message('debug',"@@@@ Product::buy_cash()");

		// $cashpoint = $this->cashpoint->get_cash_to_point($this->input->post('idx'));

		// $this->data['choice_item']['p_type']       = 'cash';
		// $this->data['choice_item']['p_type_name']  = '캐쉬 충전';
		// $this->data['choice_item']['idx']          = $cashpoint['idx'];
		// $this->data['choice_item']['cash_name']    = $cashpoint['cash_name'];
		// $this->data['choice_item']['cash']         = $cashpoint['cash'];
		// $this->data['choice_item']['price']        = $cashpoint['price_vat'];
		$this->data['cashpoint_list']   = $this->cashpoint->select_cash_to_point_list();
		
		$this->load->view('product/buy_cash_pop_v', $this->data);
	}

	/**
	 * 결제 성공시 보여줄 페이지
	 */
	function buy_ok($pltid = '') {
		log_message('debug',"@@@@ Product::buy_ok($pltid)");

		$this->data['pltid'] = $pltid;
		$this->load->view('product/buy_ok_v', $this->data);
	}

	/**
	 * 결제 실패시 보여줄 페이지
	 */
	function buy_fail($errmsg) {
		log_message('debug',"@@@@ Product::buy_fail($errmsg)");
		
		$this->data['errmsg'] = $errmsg;
		$this->load->view('product/buy_fail_v', $this->data);
	}
	
	/**
	 * 가상계좌 결제시 보여줄 페이지
	 */
	function va_waiting() {
		log_message('debug',"@@@@ Product::va_waiting()");
		
		$this->load->view('product/va_waiting_v', $this->data);
	}
	
	/**
	 * 선물받은 VIP이용권 내역 조회
	 */
	function receive_vip() {
		log_message('debug',"@@@@ Product::receive_vip()");
		
		$this->data['vip'] = $this->package->get_vip_given_history($this->data['sess_userinfo']['user_id']);
		
		$this->load->view('product/receive_vip_pop_v', $this->data);
	}
	
	function receive_vip_ok() {
		log_message('debug',"@@@@ Product::receive_vip_ok()");
		
		$this->package->update_vip_history_confirm_yn($this->input->post('idx'));
		
		echo '<script type="text/javascript">';
		echo '	opener.location.href = "/mypage/vip_status";';
		echo '	window.close();';
		echo '</script>';
		
	}
}

/* End of file premium.php */
/* Location: ./application/controllers/premium.php */